package basic_practice_1018;

import java.util.Scanner;
/**
 * @author MemoryC
 * */
public class Main {

	public static void main(String[] args) {

		Scanner scanner=new Scanner(System.in);
		
		while(scanner.hasNext()) {
			int n=scanner.nextInt();
			int r=scanner.nextInt();
            
			int num=0;
			while(n>0){
            	num+=n%r;
            	n/=r;
            }

            System.out.println(Integer.toString(num,r).toUpperCase());
		}
		scanner.close();
    }
}